/*
 * Created on Jun 9, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package screen_calibration;
import java.awt.*;
import java.awt.event.*;

import javax.swing.JPanel;

/**
 * This small program loads an image via java.awt.Toolkit and displays it in a window. 
 * You will need Java 1.1 or higher to run it successfully.
 * If you leave out the call to addWindowListener even Java 1.0 will be enough.
 * The program waits for the image to be loaded completely using MediaTracker. 
 * @author Alex Frid alex.frid@gmail.com; Ran Dror
 */
public class ImageViewer extends JPanel {
	
    private Image image;
	
    private String filePath;
    
	public ImageViewer(String fileName) {
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		
		filePath = new String(fileName);
		
		image = toolkit.getImage(filePath);
		
		MediaTracker mediaTracker = new MediaTracker(this);
		
		mediaTracker.addImage(image, 0);
		
		try
		{
			mediaTracker.waitForID(0);
		}
		catch (InterruptedException ie)
		{
			System.err.println(ie);
			System.exit(1);
		}
		setSize(image.getWidth(null), image.getHeight(null));
		
		show();
	}
	
	public void paint(Graphics graphics) {
		graphics.drawImage(image, 0, 0, null);
	}
}
